<section id="container" class="">
  <!--main content start-->
  <section id="main-content">
    <section class="wrapper">
      <!--state overview end-->
      <div class="row">
        <div class="col-lg-12">
          <section class="panel">
            <header class="panel-heading">
              拜访记录
              <i class="button-next icon-plus" onclick="location.href='#/addSysVisit'"> 新增</i>
            </header>
            <div class="panel-body">
              <div id="ctlogContainer" class="dlshouwen-grid-container"></div>
              <div id="ctlogToolBarContainer" class="dlshouwen-grid-toolbar-container"></div>
            </div>
          </section>
        </div>
      </div>
    </section>
  </section>
  <!--main content end-->
</section>

  <!-- 当前页面js文件引入 -->
  <!--<script src="js/proinfo/customer.js"></script>-->
<script type="text/javascript">
    function findVisits(CertusFormAjax) {
        var otherColumns = [{
            id: 'pro_name',
            title: '项目名称',
            type: 'string',
            width: 200,
            columnClass: 'text-center'
        },{
            id: 'customer_name',
            title: '客户名称',
            type: 'string',
            width: 150,
            columnClass: 'text-center',
        },{
            id: 'user_name',
            title: '接待人',
            type: 'string',
            width: 75,
            columnClass: 'text-center',
        },{
            id: 'visit_time',
            title: '拜访时间',
            type: 'date',
            width: 100,
            format: 'yyyy-MM-dd',
            otype:'time_stamp_ms',
            columnClass: 'text-center'
        },  {
            id: 'content',
            title: '拜访内容',
            type: 'string',
            columnClass: 'text-left',
        },{
            id: 'operation',
            title: '操作',
            width: 75,
            type: 'string',
            columnClass: 'text-center',
            resolution: function (value, record) {
                var content = '';
                var content = "";
                //计算相差多少天
                var fordate = new Date(record.create_time);
                var nfordate = $.fn.dlshouwen.grid.tools.dateFormat(fordate, "yyyy-MM-dd");

                var d = new Date();
                var start=nfordate.replace(/-/g,"/");
                var startdate=new Date(start);
                var time=d.getTime()-startdate.getTime();
                var days=parseInt(time/(1000 * 60 * 60 * 24));
                //大于三天则不能修改和删除
                if (days<=3){
                    content += '<button class="btn btn-xs btn-danger" onclick="del(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
                }
                return content;
            }
        }];
        var plistGrid;
        this.search = function () {
            $("#ctlogContainer").empty();
            $("#ctlogToolBarContainer").empty();
            CertusFormAjax.ajax("findSysVisits",{},function (response) {
                var plistOption = {
                    lang: 'zh-cn',
                    ajaxLoad: false,
                    extraWidth: 20,
                    // loadURL:'url',
                    exportFileName: '拜访记录',
                    datas: response.data,
                    columns: otherColumns,
                    gridContainer: 'ctlogContainer',
                    toolbarContainer: 'ctlogToolBarContainer',
                    tools: '',
                    pageSize: 10,
                    pageSizeLimit: [10, 15, 20]
                };
                plistGrid = $.fn.dlshouwen.grid.init(plistOption);
                plistGrid.load();
            });
        };
        search();
        this.del = function (id) {
            layer.confirm('确认删除此数据？', {
                btn: ['确定', '取消'] //按钮
            }, function (index) {
                CertusFormAjax.ajax('delVisit',{"id":id},function () {
                    layer.msg("删除成功");
                    search();
                });
            });
        }
    }
</script>